var RunLayer = cc.Layer.extend({
	arr:null,
	scene:null,
	clock:null,
	ctor:function (parent) {
		this._super();
		this.scene = parent;
		this.scene.addChild(this, 10);
		gg.main = this;
		this.init();
	},
	init:function () {
		this.callNext = cc.callFunc(function(){
			gg.flow.next();
		}, this);
		this.callKill = cc.callFunc(function(p){
			var seq = cc.sequence(cc.fadeOut(0.5),cc.callFunc(function(){
				p.removeFromParent(true);	
			}, this));
			p.runAction(seq);
		}, this); 
		
		this.callNext.retain();
		this.callKill.retain();
		//时钟
		this.clock = new Clock(this);
		// 物品库
		this.lib = new Lib(this);
		
	},
	loadFilter:function(pos){
		this.filter = new Filter(this);
		this.addChild(this.filter, 20);
		this.loadInLib(this.filter, pos, cc.p(800,350));
	},
	loadFe:function(pos){
		this.fe = new Fe(this);
		this.addChild(this.fe, 20);
		this.loadInLib(this.fe, pos, cc.p(600,250));
	},
	loadS:function(pos){
		this.s = new S(this);
		this.addChild(this.s, 20);
		this.loadInLib(this.s, pos, cc.p(600,250));
	},
	loadMagnet:function(pos){
		this.magnet = new Magnet(this);
		this.addChild(this.magnet, 19);
		this.loadInLib(this.magnet, pos, cc.p(830,440),false);
	},
	loadSpoon:function(pos){
		this.spoon = new Spoon(this);
		this.addChild(this.spoon, 20);
		this.loadInLib(this.spoon, pos, cc.p(830,410),false);
	},
	loadShelf:function(pos){
		this.shelf = new Shelf(this);
		this.addChild(this.shelf, 20);
		this.loadInLib(this.shelf, pos, cc.p(600,350));
	},
	loadSlot:function(pos){
		this.slot = new PaperSlot(this);
		this.addChild(this.slot, 19);
		this.loadInLib(this.slot, pos, cc.p(1050,200));
	},
	loadTesttube:function(pos){
		this.testtube = new Testtube(this);
		this.addChild(this.testtube, 20);
		this.loadInLib(this.testtube, pos, cc.p(800,200));
	},
	loadWood:function(pos){
		var wood = new Button(this, 8, TAG_WOOD, "#wood.png", this.callback);
		wood.setScale(0.5,0.8);
		this.loadInLib(wood, pos, cc.p(169,260));
	},
	loadLamp:function(pos){
		this.lamp = new Lamp(this);
		this.addChild(this.lamp, 20);
		this.loadInLib(this.lamp, pos, cc.p(450,200));
	},
	loadFilter2:function(pos){
		var filter = new Button(this, 8, TAG_FILTER2, "#filter.png", this.callback);
		this.loadInLib(filter, pos, cc.p(800,200));
	},
	loadMagnet2:function(pos){
		var magnet = new Button(this, 8, TAG_MAGNET2, "#magnet.png", this.callback);
		magnet.setScale(0.8);
		magnet.setRotation(45);
		magnet.setPosition(cc.p(1000,600));
		var mov0=cc.moveTo(0.6, cc.p(848,280));
		var mov1=cc.moveTo(0.6, cc.p(828,280));
		var mov2=cc.moveTo(0.6, cc.p(858,280));
		var seq=cc.sequence(mov0,mov1,mov2,mov1,mov0,cc.callFunc(function() {
			var show=new ShowTip("磁铁无法吸引生成物FeS，\n实验表面：有的金属与非金属可以发生反应，转化成化合物",cc.p(400,300))
		}, this),cc.delayTime(5),cc.callFunc(function() {
			gg.flow.next();
		}, this));
		magnet.runAction(seq);
	},
	loadInLib:function(obj, pos, tarPos,next,delay){
		obj.setPosition(pos);
		if(next == null){
			next = true;
		}
		if(delay == null){
			delay = 1;
		}		
		var ber = $.bezier(pos, tarPos, delay);
		if(next){
			var seq = cc.sequence(ber, this.callNext);
		}else{
			var seq = cc.sequence(ber);
		}	
		obj.runAction(seq);
	},
	kill:function(obj){
		var fade = cc.fadeTo(0.5,0);
		var func = cc.callfunc(function(){
			obj.removeFromParent(true);
		},this);
		var seq = cc.sequence(fade,func);
		obj.runAction(seq)
	},
	
	callback:function (p){
		var func = cc.callFunc(this.actionDone, this);
		var action=gg.flow.flow.action;
		switch(p.getTag()){
		   case TAG_NAOH_LID:
				break;
		}
	},
	actionDone:function(p){
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
			case TAG_PAPER:
				
				break;
			case TAG_SPOON:
				
				break;
		}
	},
	flowNext:function(){
		gg.flow.next();
	},
	onExit:function(){
		this._super();
		this.callNext.release();
		this.callKill.release();
	}
});